﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 计算器窗体
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //初始化组合框
            comboBox1.Items.Add("＋");
            comboBox1.Items.Add("—");
            comboBox1.Items.Add("×");
            comboBox1.Items.Add("÷");
            comboBox1.Items.Add("％");

            //初始化文本框
            label5.Text = "";
            label6.Text = "";

            //重新命名窗体
            this.Text = "Calculator(计算器)";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            float ans;
            string c = comboBox1.Text;
            float a = float.Parse(textBox1.Text);
            float b = float.Parse(textBox2.Text);
            label5.Text = "";
            label6.Text = "";
            switch (c)
            {
                case "＋":
                    ans = a + b;
                    label5.Text = ans.ToString();
                    break;
                case "—":
                    ans = a - b;
                    label5.Text = ans.ToString();
                    break;
                case "×":
                    ans = a * b;
                    label5.Text = ans.ToString();
                    break;
                case "÷":
                    if (b == 0)
                        label6.Text = "除数为0，不符合要求！";
                    else
                    {
                        ans = a / b;
                        label5.Text = ans.ToString();
                    }
                    break;
                case "％":
                    ans = a % b;
                    label5.Text = ans.ToString();
                    break;
                default:
                    break;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }
    }
}
